% cross over ethnic group
function new = CrossOver(old, pc)
[rows cols] = size(old);
for i = 1:2:rows-1 % 邻近交叉
%     if(rand<pc)
%         cpoint=round(rand*cols);
%         new(i,:)=[old(i,1:cpoint),old(i+1,cpoint+1:cols)];
%         new(i+1,:)=[old(i+1,1:cpoint),old(i,cpoint+1:cols)];
%     else
%         new(i,:)=old(i,:);
%         new(i+1,:)=old(i+1,:);
%     end

    new(i,:)=old(i,:);
    new(i+1,:)=old(i+1,:);
    if(rand<pc)
        s1 = round(rand/2*cols); 
        if s1 == 0
            s1 = 1;
        end
        s2 = round((0.5+rand/2)*cols);
        new(i,s1:s2) = old(i+1,s1:s2);
        new(i+1,s1:s2) = old(i,s1:s2);
    end
end
